//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package objects;

import common.GlobalID;
import common.Utils;
import init.StaticData;
import java.util.Iterator;
import java.util.LinkedHashMap;

public class OrderEntry implements Comparable<OrderEntry> {
    private final Integer index;
    private final Integer level;
    private final Integer receiver;
    private final LinkedHashMap<Integer, Integer> items = new LinkedHashMap();
    private Integer cash;
    private Integer exp;
    private OrderEntry.state shipped;

    public OrderEntry(Integer level, Integer receiver, Integer index) {
        this.shipped = OrderEntry.state.waiting;
        this.level = level;
        this.receiver = receiver;
        this.index = index;
    }

    public boolean isEmpty() {
        return this.receiver == null;
    }

    public Integer level() {
        return this.level;
    }

    public Integer receiver() {
        return this.receiver;
    }

    public void setCachExp(Integer cash, Integer exp) {
        this.cash = cash;
        this.exp = exp;
    }

    public void addItem(Integer id, Integer amount) {
        this.items.put(id, amount);
    }

    public LinkedHashMap<Integer, Integer> items() {
        return this.items;
    }

    public Integer index() {
        return this.index;
    }

    public Integer cash() {
        return this.cash;
    }

    public Integer exp() {
        return this.exp;
    }

    public OrderEntry.state getState() {
        return this.shipped;
    }

    public void setState(OrderEntry.state val) {
        this.shipped = val;
    }

    public boolean isReadyToShip(LinkedHashMap<Integer, Integer> inventory) {
        boolean ready = true;
        Iterator var4 = this.items().keySet().iterator();

        while(var4.hasNext()) {
            Integer id = (Integer)var4.next();
            if(!Utils.canUse(id.intValue(), ((Integer)this.items().get(id)).intValue(), inventory, false)) {
                ready = false;
                break;
            }
        }

        return ready;
    }

    public int siloscount() {
        int count = 0;
        Iterator var3 = this.items.keySet().iterator();

        while(var3.hasNext()) {
            Integer id = (Integer)var3.next();
            if(GlobalID.getClassID(id.intValue()) == 4) {
                count += ((Integer)this.items.get(id)).intValue();
            }
        }

        return count;
    }

    public String toString() {
        String val = new String();

        Integer item;
        for(Iterator var3 = this.items.keySet().iterator(); var3.hasNext(); val = val + "\"" + StaticData.getGlobalName(item) + "\"" + "=" + this.items.get(item) + " ") {
            item = (Integer)var3.next();
        }

        return this.receiver != null?this.receiver + ":" + " Lvl:" + this.level + " Exp:" + this.exp + " { " + val + "}":null;
    }

    public int compareTo(OrderEntry o) {
        return o.exp == null?-1:(this.exp == null?1:o.exp.intValue() - this.exp.intValue());
    }

    public static enum state {
        waiting,
        readyToShip,
        Shipped,
        needToCancel;

        private state() {
        }
    }
}
